<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<%
//Timestamp
final String timestamp = String.valueOf(new Date().getTime());

//User
final String username = request.getParameter( "username" );
final String password = request.getParameter("password");
final String email = request.getParameter( "email" );

//URL
final String url = request.getRequestURL().toString().replace(request.getRequestURI().substring(1), request.getContextPath()) + "/index.jsp?code="+timestamp+"&email="+email;

// SMTP Authentication settings
final String host = "smtp.gmail.com";
final String user = "laerested.utland.noanswer@gmail.com";
final String pass = "qweasdqweasd9009";
final String port = "465";

// E-Mail settings
final String to = email;
final String from = user;
final String subject = "Welcome to LUT";
final String mesg = "Your e-mail had been registered at our service under the username: "+username+ "\nIf you feel that this e-mail is the case of imposture or a fraud, please click here: ...\nIn order to procede with the registration, click here: "+url;
%>

<sql:transaction dataSource="jdbc/lut2">
    <sql:update var="count">
    INSERT INTO temp_users VALUES (?, ?, ?);
    <sql:param><%= username %></sql:param>
    <sql:param><%= password %></sql:param>
    <sql:param><%= email %></sql:param>
    </sql:update>
</sql:transaction>

<%
Properties props = System.getProperties();
        props.put("mail.smtp.host", host);
        props.put("mail.smtp.socketFactory.port", port);
        props.put("mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", port);
            
            Session mailSession = Session.getInstance(props,new javax.mail.Authenticator() { 
				protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(user, pass);
				}
			});
            
 try {

            Message message = new MimeMessage(mailSession);
            message.setContent(mesg, "text/html");
            message.setFrom(new InternetAddress(from));
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
            message.setSubject(subject);
            message.setText(mesg);

            Transport.send(message);

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }

%>